-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Avoid ODE in SignalR TestServer tests #63278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an ObjectDisposedException (ODE) that was occurring in SignalR TestServer tests by ensuring proper resource cleanup. The issue arose when moving to HostBuilder and TestServer in the DI container, where connections weren't being properly disposed before the host was closed.
- Updates connection disposal to use
await usingpattern for automatic async disposal - Ensures connections are properly closed before host disposal to prevent ObjectDisposedException
| connectionBuilder.Services.AddLogging(); | ||
| connectionBuilder.Services.AddSingleton(LoggerFactory); | ||
| var connection = connectionBuilder.Build(); | ||
| await using var connection = connectionBuilder.Build(); |
Copilot
AI
Aug 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using await using for connection disposal is correct, but ensure that the connection is explicitly stopped before disposal to prevent potential race conditions. Consider calling await connection.StopAsync() before the connection goes out of scope.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DisposeAsync does the same thing as StopAsync for the HubConnection.
| connectionBuilder.Services.AddLogging(); | ||
| connectionBuilder.Services.AddSingleton(LoggerFactory); | ||
| var connection = connectionBuilder.Build(); | ||
| await using var connection = connectionBuilder.Build(); |
Copilot
AI
Aug 15, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using await using for connection disposal is correct, but ensure that the connection is explicitly stopped before disposal to prevent potential race conditions. Consider calling await connection.StopAsync() before the connection goes out of scope.
Moving to
HostBuilderand thusTestServerin the DI container, instead of explicitly creating it, has caused an ODE to appear in this test because we weren't closing the connection but were closing the host.Should be fixed by closing the connection before closing the host.